﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace WindowsGame1
{
    public class AlienFat : Alien
    {
        float delay = 2.0f;
        int count = 5;
        bool startedShoot = false;
  
        public AlienFat()
        {
            lifePoint = 50;
            speed = 70;
            score = 500;
        }

        protected override void UpdateShootingStatus(Timer t)
        {
            bool outOfScreen = Game1.instance.IsOutOfScreen(new Rectangle((int)pos.X, (int)pos.Y, 1, 1));
            if (outOfScreen)
                return;
            else
                if (startedShoot)
                    speed *= 0.95f;
                else
                {
                    speed += 0.1f;
                    speed *= 1.1f;
                    if (speed > 110)
                        speed = 110;
                }

            delay -= t.Delta;
            
            if  (delay < 0 && count > 0 && freeze < 1.0f)
            {
                count--;
                delay = 1.0f;

                startedShoot = count != 0;

                for (int i=-4; i<=4; i++)
                {
                    Bullet b = Bullet.CreateFatBullet();
                    b.pos = pos;
                    Vector2 dir2d = new Vector2(0, 1); //  Vector2.Normalize(Game1.instance.plane.pos - pos);
                    Vector3 dir3d = new Vector3(dir2d.X, dir2d.Y,0);
                    Matrix r = Matrix.CreateRotationZ(MathHelper.ToRadians(i * 15));
                    Vector3 rdir3d = Vector3.Transform(dir3d, r);
                    b.dir = new Vector2(rdir3d.X, rdir3d.Y);

                    Game1.instance.alienBulletManager.bullets.Add(b);
                }

           }
        }


        protected override void OnEventExplode()
        {
            Game1.instance.explosionManager.AddExplosionBig(pos);
        }

    }
}
